package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    //查询所以用户及其订单
    @Select("select * from t_user")
    @Results(
            {
                    @Result(column = "id",property = "id"),
                    @Result(column = "username",property = "username"),
                    @Result(column = "password",property = "password"),
                    @Result(column = "birthday",property = "birthday"),
                    @Result(column = "id",property = "orders",javaType = List.class,
                            many = @Many(select = "com.example.demo.mapper.OrderMapper.selectByUid")
                    )

            }
    )
    List<User> selectAllUserAndOrders();

    @Select("select * from t_user where id = #{id}")
    User selectById(int id);

    // User selectUser(Integer id);
    User selectUser(@Param("id") Integer id, @Param("username") String username);

    //条件查询
//    List<User> selectAllUsers(
//            @Param("username") String username,
////            @Param("status") List<Integer> statusList,
//            @Param("gender") String gender
//    );

    //增加分页
    List<User> selectAllUsers(Page<User> page, @Param("username") String username, @Param("gender") String gender);
}
